﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;

namespace MenusSample
{
    /// <summary>
    /// 类型对应数据库配置类
    /// </summary>
    public class MenuCardConfiguration : IEntityTypeConfiguration<MenuCard>
    {
        public void Configure(EntityTypeBuilder<MenuCard> builder)
        {
            //配置表名称
            builder.ToTable("MenuCards")
                .HasKey(c => c.MenuCardId);//主键
            builder.Property(c => c.MenuCardId)
                .ValueGeneratedOnAdd();//主键为自增长
            builder.Property(c => c.Title)
                .HasMaxLength(50);//Title限制最大长度

            //关联关系
            builder.HasMany(c => c.Menus)
                .WithOne(m => m.MenuCard);

            //新增更新删除状态属性
            builder.Property<DateTime>("LastUpdated");
            builder.Property<bool>("IsDeleted");
        }
    }
}
